package com.smartplatform.controller.advices;

import com.smartplatform.dto.R;
import com.smartplatform.exception.BaseException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author 咕唧
 * @Date 2022/5/30 15:14
 * @Version 1.0
 */
@RestControllerAdvice//controller的增强
public class MyExceptionAdvice {

    @ExceptionHandler(BaseException.class)
    public R processBaseException(BaseException exception) {
        return R.setResult(exception.getCode(), exception.getMessage(), null);
    }

    @ExceptionHandler(Exception.class)
    public R processException(Exception e) {
        e.printStackTrace();
        return R.setError();
    }
}
